package vashion.azeroth.core.personal.pojo;

import org.apache.commons.lang3.math.NumberUtils;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.ObjectMapper;

import vashion.azeroth.core.pojo.BaseObject;

import java.io.IOException;
import java.util.Date;

public class PersonalPublishFiles extends BaseObject {

    private static final long serialVersionUID = -3258578721702381691L;

    /**
     * 文章表主键id
     */
    private Long publishFileId;

    /**
     * 用户id
     */
    private Long memberId;

    /**
     * 用户名
     */
    private String memberName;

    /**
     * 发布文章的标题
     */
    private String title;

    /**
     * 发布文章的内容
     */
    private String content;

    /**
     * 横坐标
     */
    private String posx;

    /**
     * 纵坐标
     */
    private String posy;

    /**
     * 发布者详细位置信息
     */
    private String coordinateAddress;

    /**
     * 文章中所带有的标签（非图片标签，与标签表的数据无关）
     */
//    @JsonIgnore
    private String tags;

    /**
     * 发布文章的状态
     * <p/>
     * 0：文章已删除； 1：文章未删除 2：文章被后台设置成精选
     */
    private Integer status;

    /**
     * 发布文章的图片url
     */
    private String feedPic;

    /**
     * 联系人信息（发布文章时带入的联系人信息）
     */
    private String contactLabelRange;

    /**
     * 地址开启标志（发布文章时标志是否开启位置）
     * <p/>
     * 0：不开启位置， 1：开启位置
     */
    private int posFlag;

    /**
     * 获取文章时的排序规则
     * <p/>
     * 1：获取文章按时间排序， 2：获取文章按精选排序， 3：获取文章按关注的人所发表的文章排序
     */
    private Integer sortFlag;

    /**
     * 创建时间
     */
    private Date timeAdd;

    /**
     * 修改时间
     */
    private Date timeEdit;


    /**
     * 文章关联的商品信息
     */
    private String itemInfo;

    /**
     * 备注
     */
    private String remark;

    /**
     * 点赞数量
     */
    private Integer approvalCount;

    /**
     * 收藏数量
     */
    private Integer favoriteCount;

    /**
     * 评论数量
     */
    private Integer commentCount;

    /**
     * 帖子删除时间
     */
    private Date timeDel;


    /**
     * 删除帖子的会员
     */
    private Integer delMember;


    /**
     * 当前用户是否点赞
     * <p/>
     * 0：帖子未点赞； 1：帖子已点赞
     */
    private Integer approvalStatus;

    /**
     * 当前用户是否收藏
     * <p/>
     * 0：帖子未收藏； 1：帖子已收藏
     */
    private Integer favoriteStatus;

    /**
     * 当前用户是否评论
     * <p/>
     * 0：帖子未评论；1：帖子已评论
     */
    private Integer commentStatus;


    public Integer getApprovalStatus() {
        return approvalStatus;
    }

    public void setApprovalStatus(Integer approvalStatus) {
        this.approvalStatus = approvalStatus;
    }

    public Integer getFavoriteStatus() {
        return favoriteStatus;
    }

    public void setFavoriteStatus(Integer favoriteStatus) {
        this.favoriteStatus = favoriteStatus;
    }

    public Integer getCommentStatus() {
        return commentStatus;
    }

    public void setCommentStatus(Integer commentStatus) {
        this.commentStatus = commentStatus;
    }

    public Date getTimeDel() {
        return timeDel;
    }

    public void setTimeDel(Date timeDel) {
        this.timeDel = timeDel;
    }

    public Integer getDelMember() {
        return delMember;
    }

    public void setDelMember(Integer delMember) {
        this.delMember = delMember;
    }

    public Integer getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(Integer commentCount) {
        this.commentCount = commentCount;
    }

    public Integer getApprovalCount() {
        return approvalCount;
    }

    public void setApprovalCount(Integer approvalCount) {
        this.approvalCount = approvalCount;
    }

    public Integer getFavoriteCount() {
        return favoriteCount;
    }

    public void setFavoriteCount(Integer favoriteCount) {
        this.favoriteCount = favoriteCount;
    }


    /**
     * @return the itemInfo
     */
    public String getItemInfo() {
        return itemInfo;
    }

    /**
     * @param itemInfo the itemInfo to set
     */
    public void setItemInfo(String itemInfo) {
        this.itemInfo = itemInfo;
    }

    public Long getPublishFileId() {
        return publishFileId;
    }

    public void setPublishFileId(Long publishFileId) {
        this.publishFileId = publishFileId;
    }


    public Long getMemberId() {
		return memberId;
	}

	public void setMemberId(Long memberId) {
		this.memberId = memberId;
	}

	public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPosx() {
        return posx;
    }

    public void setPosx(String posx) {
        this.posx = posx;
    }

    public String getPosy() {
        return posy;
    }

    public void setPosy(String posy) {
        this.posy = posy;
    }

    public String getCoordinateAddress() {
        return coordinateAddress;
    }

    public void setCoordinateAddress(String coordinateAddress) {
        this.coordinateAddress = coordinateAddress;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Date getTimeAdd() {
        return timeAdd;
    }

    public void setTimeAdd(Date timeAdd) {
        this.timeAdd = timeAdd;
    }

    public Date getTimeEdit() {
        return timeEdit;
    }

    public void setTimeEdit(Date timeEdit) {
        this.timeEdit = timeEdit;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getFeedPic() {
        return feedPic;
    }

    public void setFeedPic(String feedPic) {
        this.feedPic = feedPic;
    }

    public String getContactLabelRange() {
        return contactLabelRange;
    }

    public void setContactLabelRange(String contactLabelRange) {
        this.contactLabelRange = contactLabelRange;
    }

    /**
     * @return the sortFlag
     */
    public Integer getSortFlag() {
        return sortFlag;
    }

    /**
     * @param sortFlag the sortFlag to set
     */
    public void setSortFlag(int sortFlag) {
        this.sortFlag = sortFlag;
    }

    /**
     * @return the posFlag
     */
    public int getPosFlag() {
        return posFlag;
    }

    /**
     * @param posFlag the posFlag to set
     */
    public void setPosFlag(int posFlag) {
        this.posFlag = posFlag;
    }

    @JsonIgnore
    public Long getItemIdFromTag() throws IOException {

        String tags = this.getTags();
        ObjectMapper mapper = new ObjectMapper();
        FeedTag[] feedTags = mapper.readValue(tags, FeedTag[].class);
        for (int j = 0; j < feedTags.length; j++) {
            if (feedTags[j].getGoodID().equals("")) {
                continue;
            } else {
                return NumberUtils.toLong(feedTags[j].getGoodID());
            }
        }
        return null;
    }
}